package com.yonyou.brigade.ybz.controller;

import com.alibaba.fastjson.JSONObject;
import com.yonyou.brigade.ybz.service.ICnvRegisterService;
import com.yonyou.brigade.ybz.service.IConvertService;
import com.yonyou.ybzboot.starter.common.exception.BusinessException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * 通过转换平台转换数据
 *
 * @Auther: kfw
 * @Date: 2018/8/21 10:22
 */
@RestController
@RequestMapping("/ybz/cnv")
public class CnvConvertController {
    @Autowired
    @Qualifier("convertServiceImpl")
    private IConvertService convertService;

    @Autowired
    @Qualifier("cnvRegisterServiceImpl")
    private ICnvRegisterService cnvRegisterService;
    /**
     * 一键转换平台注册
     *
     * @Auther: kfw
     * @Return: JSONArray 转换后的数据
     * @Date: 2018/8/21 10:23
     */
    @RequestMapping(value = "/register")
    public Boolean register(@RequestBody Map params) {
        String userId = params.get("userId").toString();
        String tenantId = params.get("tenantId").toString();
        /*if (StringUtils.isEmpty(userId) || StringUtils.isEmpty(tenantId))
            return "用户或租户为空";*/
        boolean registerResult = cnvRegisterService.registerAll(userId, tenantId);
        if (registerResult){
            return registerResult;
        }else {
            throw new BusinessException(500010, "第三方问题", "调用友账表转换平台出错！");
        }
    }

    /**
     * 通过转换平台转换数据
     *
     * @Auther: kfw
     * @Return: JSONArray 转换后的数据
     * @Date: 2018/8/21 10:23
     */
    @RequestMapping(value = "/convert")
    public JSONObject convert() {


        String userId = "5dbb8df8-0956-4cd1-9da3-43b180069f0f";
        String tenantId = "zrez2bx9";
        String cookie = "test=visible";
        String billtypeCode = "flight_order";
        String systemCode = "brigade";
        String bill = "{\n" +
                "\t\"orderNo\": 1400548451844,\n" +
                "\t\"publicOrPriveate\": \"1\",\n" +
                "\t\"isDomc\": \"D\",\n" +
                "\t\"preiumReason\": \"溢价原因\",\n" +
                "\t\"orderStatus\": \"NW\",\n" +
                "\t\"paymentPrice\": 1524,\n" +
                "\t\"farePrice\": 1200,\n" +
                "\t\"taxPrice\": 80,\n" +
                "\t\"psgCount\": 2,\n" +
                "\t\"ordertype\": \"N\",\n" +
                "\t\"refundPrice\": 1000,\n" +
                "\t\"tPPrcie\": 30,\n" +
                "\t\"tripType\": \" RT\",\n" +
                "\t\"isCheck\": \"N\",\n" +
                "\t\"isAllowRefund\": \"Y\",\n" +
                "\t\"allowPayDate\": \"2015-03-19 12:12:12\",\n" +
                "\t\"refundMark\": \"商家不允许退票\",\n" +
                "\t\"verifyType\": \"1\",\n" +
                "\t\"headUserName\": \"张三\",\n" +
                "\t\"flowBaseID\": \"12123\",\n" +
                "\t\"isAllowCheck\": \"1\",\n" +
                "\t\"sumCounterFee\": \"0\",\n" +
                "\t\"sumInsMoney\": \"0\",\n" +
                "\t\"relatedNo\": \"8150101020102\",\n" +
                "\t\"relatedType\": \"0\",\n" +
                "\t\"isPurchase\": \"Y\",\n" +
                "\t\"purchaseCustName\": \"企业验证名称\",\n" +
                "\t\"purchaseVerify\": \"CD\",\n" +
                "\t\"isHS\": \"Y\",\n" +
                "\t\"hsTitle\": \"官网\",\n" +
                "\t\"createBy\": \"demo1\",\n" +
                "\t\"carrierName \": \"国航\",\n" +
                "\t\"boardPoint\": \"HKD\",\n" +
                "\t\"boardPointName\": \"香港\",\n" +
                "\t\"boardPointAirPortName\": \"香港机场\",\n" +
                "\t\"boardPointAT \": \"T2\",\n" +
                "\t\"departureDate\": \"2014-12-20\",\n" +
                "\t\"departureTime\": \"08:30\",\n" +
                "\t\"offPoint\": \"PEK\",\n" +
                "\t\"offPointName\": \"北京\",\n" +
                "\t\"offPointAirPortName\": \"首都机场\",\n" +
                "\t\"offPointAT \": \"T1\",\n" +
                "\t\"arriveDate\": \"2014-12-20\",\n" +
                "\t\"arriveTime\": \"11:45\",\n" +
                "\t\"flightNO\": \"CA118\",\n" +
                "\t\"aircraft\": \"747 机型\",\n" +
                "\t\"timeSpan\": \"1 小时 20 分\",\n" +
                "\t\"tGQ\": \"退票规定：退！改签规定：改！\",\n" +
                "\t\"yprice\": 710,\n" +
                "\t\"classRebate\": \"80 折扣\",\n" +
                "\t\"psgName\": \"lisa\",\n" +
                "\t\"psgType\": \"ADT\",\n" +
                "\t\"cardType\": \"NI\",\n" +
                "\t\"cardNo\": \"1102456416516566546546546\",\n" +
                "\t\"costCenter\": \"结算部\",\n" +
                "\t\"ticketNO\": \"9991564164161651\",\n" +
                "\t\"ticketStatus\": \"\",\n" +
                "\t\"departmentName\": \"总部\",\n" +
                "\t\"isAllowRefund\": \"Y\",\n" +
                "\t\"psgRefundPrice\": \"0\",\n" +
                "\t\"psgTPPrcie\": \"0\",\n" +
                "\t\"counterFee\": \"0\",\n" +
                "\t\"isRuleOver\": \"Y\",\n" +
                "\t\"tPCounterFee\": \"0\",\n" +
                "\t\"insId\": \"12\",\n" +
                "\t\"insName\": \"0\",\n" +
                "\t\"insCount\": \"0\",\n" +
                "\t\"insMoney\": \"0\",\n" +
                "\t\"purchaseBank\": \"\",\n" +
                "\t\"isCusPsg\": \"1\"\n" +
                "}";
        JSONObject billdata = JSONObject.parseObject(bill);
        return convertService.convert(billtypeCode, systemCode, userId, tenantId, cookie, billdata);
    }

    /**
     * 通过转换平台转换数据
     *
     * @Auther: kfw
     * @Return: JSONArray 转换后的数据
     * @Date: 2018/8/21 10:23
     */
    @RequestMapping(value = "/yihaoConvertToOrderCenter")
    public JSONObject yihaoConvertToOrderCenter() {


        String userId = "5dbb8df8-0956-4cd1-9da3-43b180069f0f";
        String tenantId = "zrez2bx9";
        String cookie = "test=visible";
        String billtypeCode = "yihao_tradetype";
        String systemCode = "brigade";
        String bill = "{\n" +
                "            \"subBudgetNo\":\"\",\n" +
                "            \"orderMoney\":113,\n" +
                "            \"orderId\":\"18101710385887476232x01602\",\n" +
                "            \"passengerPassportName\":\"\",\n" +
                "            \"airTicketSalePrice\":\"113.00\",\n" +
                "            \"outTMCSupplyID\":\"\",\n" +
                "            \"budgetNo\":\"\",\n" +
                "            \"tripApplyInfoSource\":\"\",\n" +
                "            \"payFee\":0.68,\n" +
                "            \"customerCostCenterName\":\"\",\n" +
                "            \"ticketTotalMoney\":113,\n" +
                "            \"originalTotalPrice\":113,\n" +
                "            \"price\":113,\n" +
                "            \"ticketNoState\":\"\",\n" +
                "            \"billNo\":\"\",\n" +
                "            \"projectCostCenterID\":\"\",\n" +
                "            \"bigPNR\":\"\",\n" +
                "            \"customerSubjectrName\":\"\",\n" +
                "            \"overStandardDetail\":\"\",\n" +
                "            \"pNR\":\"\",\n" +
                "            \"customerCostCenterID\":\"\",\n" +
                "            \"travelAppTypeName\":\"\",\n" +
                "            \"applicationInfoID\":\"\",\n" +
                "            \"projectSubjectrName\":\"\",\n" +
                "            \"insuranceName\":\"\",\n" +
                "            \"shiftNo\":\"如家快捷酒店丽江客运站店\",\n" +
                "            \"cabin\":\"商务大床房B\",\n" +
                "            \"deptCostCenterName\":\"\",\n" +
                "            \"passengersName\":\"昭阳\",\n" +
                "            \"costCenterApproveName\":\"\",\n" +
                "            \"travelSceneName\":\"出差\",\n" +
                "            \"overStandardTypeName\":\"\",\n" +
                "            \"arriveTime\":\"2018-11-06 00:00:00\",\n" +
                "            \"corporationApplyNo\":\"\",\n" +
                "            \"orderUserOutStaffNo\":\"\",\n" +
                "            \"originalOrderId\":\"\",\n" +
                "            \"oriDiscount\":\"\",\n" +
                "            \"invoiceTypeDesc\":\"专票\",\n" +
                "            \"orderUserNo\":\"20180419105459090501\",\n" +
                "            \"otherNo\":\"\",\n" +
                "            \"tmcName\":\"四川海岛印象旅行社有限公司\",\n" +
                "            \"insurancePayFee\":0,\n" +
                "            \"isOverStandard\":0,\n" +
                "            \"finallySupplyName\":\"如家快捷\",\n" +
                "            \"tmcsupplyID\":\"20180426173322237176\",\n" +
                "            \"payTypeName\":\"月结\",\n" +
                "            \"insuranceNo\":\"\",\n" +
                "            \"originalKeyId\":\"\",\n" +
                "            \"passengerStaffNo\":\"20180921160554472404\",\n" +
                "            \"travel\":\"2018-11-05 1晚 如家快捷酒店丽江客运站店\",\n" +
                "            \"projectCostCenterCode\":\"\",\n" +
                "            \"projectCostCenterRatios\":\"\",\n" +
                "            \"beneficiaryTypeDesc\":\"上海趣卫\",\n" +
                "            \"projectCostCenterPrices\":\"\",\n" +
                "            \"overBookingReason\":\"\",\n" +
                "            \"passengerOutStaffNo\":\"\",\n" +
                "            \"insuranceRealMoney\":20,\n" +
                "            \"deptSubjectrName\":\"\",\n" +
                "            \"productTypeName\":\"国内酒店\",\n" +
                "            \"departmentName\":\"差旅壹号测试企业\",\n" +
                "            \"serviceFee\":0,\n" +
                "            \"deptCostCenterCode\":\"\",\n" +
                "            \"travelTime\":\"2018-11-05 00:00:00\",\n" +
                "            \"deptCostCenterID\":\"\",\n" +
                "            \"orderSourceName\":\"IOS\",\n" +
                "            \"startAddress\":\"丽江市古城区康仲路2号\",\n" +
                "            \"airOilFee\":0,\n" +
                "            \"count\":1,\n" +
                "            \"aheadOfBookDays\":19,\n" +
                "            \"tripApplyReason\":\"\",\n" +
                "            \"publicPrice\":\"113.00\",\n" +
                "            \"tradeTime\":\"2018-10-17 10:46:19\",\n" +
                "            \"productSubTypeName\":\"出票\",\n" +
                "            \"productLevel\":\"经济型\",\n" +
                "            \"travelAppTypeId\":\"0.0\",\n" +
                "            \"customerCostCenterCode\":\"\",\n" +
                "            \"handleChargeFee\":0,\n" +
                "            \"customerSubjectCode\":\"\",\n" +
                "            \"deptSubjectCode\":\"\",\n" +
                "            \"payStateName\":\"房态确认成功\",\n" +
                "            \"insuranceMoney\":30,\n" +
                "            \"keyId\":\"181017104823658179\",\n" +
                "            \"projectSubjectCode\":\"\",\n" +
                "            \"bookTypeName\":\"自助预定\",\n" +
                "            \"remark\":\"\",\n" +
                "            \"orderUserName\":\"昭阳\",\n" +
                "            \"tMCSupplyName\":\"直连-如家\",\n" +
                "            \"travelType\":1,\n" +
                "            \"ticketTotalPrice\":113,\n" +
                "            \"passengerDepartmentName\":\"差旅壹号测试企业\",\n" +
                "            \"isOverStandardName\":\"未超标\",\n" +
                "            \"corpOverStandardApplyNo\":\"\",\n" +
                "            \"productType\":3,\n" +
                "            \"projectCostCenterName\":\"\",\n" +
                "            \"overStandardApplyNo\":\"\",\n" +
                "            \"overStandardApplySource\":\"\",\n" +
                "            \"deptCostCenterRatios\":\"\",\n" +
                "            \"corpName\":\"差旅壹号测试企业\",\n" +
                "            \"priceServiceTotalFee\":113,\n" +
                "            \"discountMoney\":0,\n" +
                "            \"customerCostCenterRatios\":\"\",\n" +
                "            \"overStandardApplyReason\":\"\",\n" +
                "            \"travelTypeName\":\"因公出行\",\n" +
                "            \"customerCostCenterPrices\":\"\",\n" +
                "            \"calculateDiscount\":\"\",\n" +
                "            \"arriveAddress\":\"丽江\",\n" +
                "            \"tmcNo\":\"20160512144219375328\",\n" +
                "            \"budgetApplyNo\":\"\",\n" +
                "            \"deptCostCenterPrices\":\"\"\n" +
                "        }";
        JSONObject billdata = JSONObject.parseObject(bill);
        return convertService.convert(billtypeCode, systemCode, userId, tenantId, cookie, billdata);
    }
}

